/**
 * @USER: Administrator
 * @DATE: 2024/10/5 上午10:49
 * @VERSION: 1.0.0
 */
public class LC2717 {
    public static void main(String[] args) {

    }

    public int semiOrderedPermutation(int[] nums) {
        int n = nums.length;
        int minIndex = 0,maxIndex = 0;
        for (int i = 0; i < n; i++) {
            if (nums[i]==1){
                minIndex = i;
            }
            if (nums[i]== n){
                maxIndex = i;
            }
        }


        return minIndex+(n-1-maxIndex)-(minIndex>maxIndex?1:0);
    }

}
